package com.gm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Administrator on 13-12-21.
 */
public class UiPanel extends JPanel {

   public UiPanel(Component c)
   {
       super();
       this.parent=c;

       UIManager.LookAndFeelInfo[] infos=UIManager.getInstalledLookAndFeels();

       for(UIManager.LookAndFeelInfo info:infos)
       {
            makeButton(info.getName(),info.getClassName());
       }
   }

    void makeButton(String title,final String className)
    {
        JButton btn=new JButton(title);

        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(className);
                    SwingUtilities.updateComponentTreeUI(UiPanel.this);
                } catch (ClassNotFoundException e1) {
                    e1.printStackTrace();
                } catch (InstantiationException e1) {
                    e1.printStackTrace();
                } catch (IllegalAccessException e1) {
                    e1.printStackTrace();
                } catch (UnsupportedLookAndFeelException e1) {
                    e1.printStackTrace();
                }
            }
        });

        this.add(btn);
    }

    private Component parent;
}
